package Queue;

class MyQueue {
  static class ListNode{
    public int val;
    public ListNode next;
    public ListNode prev;

    public ListNode(int val) {
      this.val = val;
    }
  }
  public  ListNode head;
  public  ListNode last;

    //将元素 x 推到队列的末尾
    public void push(int val) {
      ListNode node = new ListNode(val);
      if(head == null){
        head = last =head;
      }else{
        last.next = node;
        node.prev = last;
        last = node;
      }
    }
    //从队列的开头移除并返回元素
    public int pop() {
      if(head == null){
        return -1;
      }
      int val = -1;
      if(head.next == null){
             val = head.val;
             head =null;
             last = null;
             return val;
      }
      val = head.val;
      head = head.next;
      head.prev = null;
      return val;
    }
  //如果队列为空，返回 true ；否则，返回 false

  public boolean empty() {
    return head == null;

  }
    //返回队列开头的元素
    public int peek() {
      if(head == null){
        return  -1;
      }
      return head.val;

    }

}